home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_360 / uucp / uucp0.lzh / src / anews / reply.c < prev    next >
C/C++ Source or Header  |  1990-05-18  |  3KB  |  169 lines

  1.  
  2. /*
  3.  *  REPLY.C
  4.  *
  5.  *  Reply to sender of article (creates, edits a file, then pipes it through
  6.  *  sendmail)
  7.  */
  8.  
  9. #include "news.h"
  10. #include <time.h>
  11.  
  12. static char Buf[256];
  13.  
  14. char *findheader();
  15. char *findheaderNoNull();
  16.  
  17. static char *TempFileName = "T:anews.post.tmp";
  18.  
  19. /*
  20.  *  NOTE: fp can be NULL
  21.  */
  22.  
  23. void
  24. reply(cmd, fp, group)
  25. int cmd;
  26. FILE *fp;
  27. const char *group;
  28. {
  29.     FILE *fo = fopen(TempFileName, "w");
  30.     char *ptr;
  31.     char *user       = FindConfig(USERNAME);
  32.     char *realname = FindConfig(REALNAME);
  33.     int yes = 0;
  34.     time_t t = time(NULL);
  35.     int seq = GetSequence(0);
  36.     static char *envuser;
  37.     static char *envrealname;
  38.  
  39.     if (fo == NULL) {
  40.     printf("can't create %s\n", TempFileName);
  41.     return;
  42.     }
  43.  
  44.     if (user == NULL || realname == NULL) {
  45.     printf("Incomplete Configuration, one of:\n");
  46.     printf("\t%s %s\n", USERNAME, REALNAME);
  47.     fclose(fo);
  48.     remove(TempFileName);
  49.     return;
  50.     }
  51.  
  52.     /*
  53.      *    Enviroment variable overides
  54.      */
  55.  
  56.     if (envuser == NULL)
  57.     envuser = MallocEnviro("USER");
  58.     if (envrealname == NULL)
  59.     envrealname = MallocEnviro("REALNAME");
  60.     if (envuser)
  61.     user = envuser;
  62.     if (envrealname)
  63.     realname = envrealname;
  64.  
  65.     /*
  66.      *    Create email template that can be sent through sendmail, handle
  67.      *    signature and optional included text.
  68.      */
  69.  
  70.     {
  71.     char *to;
  72.  
  73.     if ((to = findheader(fp, "Reply-To:")) == NULL)
  74.         to = findheader(fp, "From:");
  75.     if (to) {
  76.         fprintf(fo, "To: %s\n", to);
  77.         free(to);
  78.     } else {
  79.         fprintf(fo, "To: \n");
  80.     }
  81.     }
  82.     fprintf(fo, "Cc: \n");
  83.     fprintf(fo, "Subject: ");
  84.  
  85.     if (fp)
  86.     fprintf(fo, "Re: ");
  87.     if (ptr = findheader(fp, "Subject:")) {
  88.     char *xp = ptr;
  89.     if (strnicmp(xp, "re:", 3) == 0)
  90.         xp += 3;
  91.     while (*xp == ' ' || *xp == 9)
  92.         ++xp;
  93.     fprintf(fo, "%s", xp);
  94.     free(ptr);
  95.     }
  96.     fputs("\n", fo);
  97.  
  98.     fputs("\n", fo);
  99.  
  100.     if (fp && cmd >= 'A' && cmd <= 'Z') {
  101.     rewind(fp);
  102.     while (fgets(Buf, sizeof(Buf), fp) && Buf[0] != '\n');
  103.     while (fgets(Buf, sizeof(Buf), fp)) {
  104.         fprintf(fo, ">");
  105.         fputs(Buf, fo);
  106.     }
  107.     }
  108.     fputs("\n", fo);
  109.  
  110.     /*
  111.      *    append signature
  112.      */
  113.  
  114.     {
  115.     FILE *fi;
  116.  
  117.     sprintf(Buf, "%s.signature", user);
  118.     fi = openlib(Buf);
  119.     if (fi == NULL)
  120.         fi = openlib(".signature");
  121.     if (fi) {
  122.         fputs("--\n", fo);
  123.         while (fgets(Buf, sizeof(Buf), fi))
  124.         fputs(Buf, fo);
  125.         fclose(fi);
  126.     } else {
  127.         puts("Warning, no .signature file!");
  128.     }
  129.     }
  130.  
  131.     fclose(fo);
  132.  
  133.     /*
  134.      *    Edit the file
  135.      */
  136.  
  137.     sprintf(Buf, "%s %s", GetConfig(NEWSEDITOR, GetConfig(EDITOR, "dme")), TempFileName);
  138.     system(Buf);
  139.  
  140.     /*
  141.      *    want to post this?
  142.      */
  143.  
  144.     cooked(stdin);
  145.     printf("Do you want to send this? 'y' or 'n' :");
  146.     fflush(stdout);
  147.     while (fgets(Buf, sizeof(Buf), stdin)) {
  148.     if (strcmp(Buf, "y\n") == 0 || strcmp(Buf, "yes\n") == 0) {
  149.         yes = 1;
  150.         break;
  151.     }
  152.     if (strcmp(Buf, "n\n") == 0 || strcmp(Buf, "no\n") == 0) {
  153.         break;
  154.     }
  155.     printf("'y' or 'n' please: ");
  156.     fflush(stdout);
  157.     }
  158.  
  159.     raw(stdin);
  160.     if (yes) {
  161.     sprintf(Buf, "%s < %s -f %s", GetConfigProgram(SENDMAIL), TempFileName, user);
  162.     system(Buf);
  163.     remove(TempFileName);
  164.     } else {
  165.     printf("File left as %s\n", TempFileName);
  166.     }
  167. }
  168.  
  169.